<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(":button:eq(1)").click(function(){
		location.href="ToAddUserServlet";
	});
	$(".page:first").click(function(){
		currentPage = 1;
		getList();
	});
	$(".page:eq(1)").click(function(){
		if(currentPage==1){
			alert("当前已经是第一页啦");
		}else{
			currentPage--;
			getList();
		}
	});
	$(".page:eq(2)").click(function(){
		if(currentPage==totalPage){
			alert("当前已经是最后一页啦");
		}else{
			currentPage++;
			getList();
		}
	});
	$(".page:eq(3)").click(function(){
		currentPage = totalPage;
		getList();
	});
	$(":button:first").click(function(){
		currentPage = 1;
		getList();
	});
	function getList(){
		var namekey = $("#namekey").val();
		var roleid = $("#roleid").val();
		location.href="GetUserListServlet?currentPage="+currentPage+"&namekey="+namekey+"&roleid="+roleid;
	}
});
function del(id){
	if(confirm("是否确定删除？")){
		location.href="DelUserServlet?id="+id+"&currentPage="+currentPage;
	}
}
function update(id,name,password,roleid){
	location.href="ToAddUserServlet?id="+id+"&name="+name+"&password="+password+"&roleid="+roleid;
}
</script>
</head>
<body>
用户名：<input type="text" id="namekey" value="${param.namekey }">
角色：
<servlet id="roleid">
<option value="0">请选择</option>
<c:forEach items="${roles}" var="r">
	<option value="${r.roleId}" ${r.roleId==param.roleid?"selected":""}>${r.roleName }</option>
</c:forEach>
</servlet>
<input type="button" value="搜索">
<input type="button" value="添加">
<table border="1" ="80%">
 <tr><th>ID</th><th>用户名</th><th>密码</th><th>角色</th><th>操作</th></tr>
 <c:forEach items="${list}" var="b">
		<tr>
			<td>${b.userId}</td>
			<td>${b.userName}</td>
			<td>${b.userPassword}</td>
			<td>${b.role.roleName}</td>
			<td>
				<input type="button" value="删除" onclick="del(${b.userId})">
				<input type="button" value="修改" onclick="update(${b.userId},'${b.userName}','${b.userPassword}',${b.role.roleId})">
			</td>
		</tr>
	</c:forEach>
</table>
</body>
</html>